//打开EDA软件脚本
/* eslint-disable */
window.protocolCheck = function (uri, failCb, successCb) {
  function failCallback() {
    failCb && failCb()
  }

  function successCallback() {
    successCb && successCb()
  }

  if (navigator.msLaunchUri) {
    //for IE and Edge in Win 8 and Win 10
    openUriWithMsLaunchUri(uri, failCb, successCallback)
  } else {
    var browser = checkBrowser()

    /*if (browser.isFirefox) {
            openUriUsingFirefox(uri, failCallback, successCallback);
        } else */
    if (browser.isIE) {
      openUriUsingIEInOlderWindows(uri, failCallback, successCallback)
    } else {
      openUriWithHiddenFrame(uri, failCallback, successCallback)
    }
  }
}
window.openUriWithMsLaunchUri = function (uri, failCb, successCb) {
  navigator.msLaunchUri(uri, successCb, failCb)
}
window.checkBrowser = function () {
  var isOpera = !!window.opera || navigator.userAgent.indexOf(" OPR/") >= 0
  return {
    isOpera: isOpera,
    isFirefox: typeof InstallTrigger !== "undefined",
    isSafari: Object.prototype.toString.call(window.HTMLElement).indexOf("Constructor") > 0,
    isChrome: !!window.chrome && !isOpera,
    isIE: false || !!document.documentMode, // At least IE6
  }
}
window.openUriUsingIEInOlderWindows = function (uri, failCb, successCb) {
  if (getInternetExplorerVersion() === 10) {
    openUriWithHiddenFrame(uri, failCb, successCb)
  } else if (getInternetExplorerVersion() === 9) {
    openUriWithAgent(uri, failCb, successCb)
  } else if (getInternetExplorerVersion() === 11) {
    openUriWithAgent(uri, failCb, successCb)
  } else {
    openUriWithAgent(uri, failCb, successCb)
  }
}
window.openUriWithHiddenFrame = function (uri, failCb, successCb) {
  var iframe = document.getElementById("hiddenIframe")
  if (!iframe) {
    iframe = _createHiddenIframe(document.body, "about:blank")
  }
  iframe.contentWindow.location.href = uri
  successCb()
}
window._createHiddenIframe = function (target, uri) {
  var iframe = document.createElement("iframe")
  iframe.src = uri
  iframe.id = "hiddenIframe"
  iframe.style.display = "none"
  target.appendChild(iframe)

  return iframe
}

window.getInternetExplorerVersion = function () {
  var rv = -1
  if (navigator.appName === "Microsoft Internet Explorer") {
    var ua = navigator.userAgent
    var re = new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")
    if (re.exec(ua) != null) rv = parseFloat(RegExp.$1)
  } else if (navigator.appName === "Netscape") {
    var ua = navigator.userAgent
    var re = new RegExp("Trident/.*rv:([0-9]{1,}[.0-9]{0,})")
    if (re.exec(ua) != null) {
      rv = parseFloat(RegExp.$1)
    }
  }
  return rv
}
/* eslint-enable */
